<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item>家族录入</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表单输入 -->
    <div class="FFormBox">
      <el-form ref="FRef" :model="FForm" :rules="FRules" class="FForm_sty">
        <el-form-item prop="fid">
          <el-input v-model="FForm.id">
            <template slot="prepend">家族ID</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="fuser_id">
          <el-input v-model="FForm.uid">
            <template slot="prepend">组长</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="f_name">
          <el-input v-model="FForm.uname">
            <template slot="prepend">家谱名称</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="f_story">
          <el-input v-model="FForm.story">
            <template slot="prepend">故事</template>
          </el-input>
        </el-form-item>
         <el-form-item prop="f_time">
          <el-input v-model="FForm.utime">
            <template slot="prepend">创建时间</template>
          </el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="inserUser" round>录入</el-button>
          <el-button type="info" @click="resetConnectionForm" round>重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 提交弹窗 -->
      <el-dialog title="提示" :visible.sync="sucessVisible" width="30%">
        <span>确定录入？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sucessVisible = false">取 消</el-button>
          <el-button type="primary" @click="sucessVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      FForm: {
        id: '',
        uid: '',
        uname: '',
        story: '',
        utime: ''
      },
      // 输入规则
      FFormRules: {
        id: [
          { required: true, message: '请输入家族ID', trigger: 'blur' }
        ],
        uid: [
          { required: true, message: '请输入组长ID', trigger: 'blur' }
        ],
        uname: [
          { required: true, message: '请输入家族名称', trigger: 'blur' }
        ],
        story: [
          { required: true, message: '请输入家族故事', trigger: 'blur' }
        ],
        utime: [
          { require: true, message: '请输入创建时间', trigger: 'blur' }
        ]
      },
      sucessVisible: false
    }
  },
  methods: {
    // 校验规则
    resetFForm() {
      this.$refs.FFormRef.resetFields()
    },
    // 提交用户
    inserUser() {
      const { data: res } = this.$http.post('familyt', {
        f_id: this.FForm.id,
        fuser_id: this.FForm.uid,
        f_name: this.FForm.uname,
        f_story: this.FForm.story,
        f_time: this.FForm.utime
      })
      this.emidtsucess()
      console.log(res)
    },
    // 提交成功提示
    emidtsucess() {
      this.sucessVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.el-form-item {
  width: 500px;
}

.ConnectionFormBox {
  background-color: #fffffb;
  height: 600px;
  width: 1210px;
  border-radius: 5px;
  margin-left: 10px;
}

.ConnectionForm_sty {
  position: absolute;
  padding: 30px 60px 30px;
  box-sizing: border-box;
}

.btns {
  display: flex;
  justify-content: flex-start;
  margin-top: 60px;
}
</style>
